package hamaster.jpbc.crypt;

import static hamaster.jpbc.crypt.rc4.SimpleRC4Crypter.decrypt;
import static hamaster.jpbc.crypt.rc4.SimpleRC4Crypter.encrypt;

import hamaster.jpbc.pbc.PBCDriver;

import java.util.ArrayList;
import java.util.List;

public final class KeysUtil {

	public static String encryptKeys(List<byte[]> keys, String key) {
		StringBuffer hex = new StringBuffer();
		for (byte[] bs : keys) {
			hex.append(PBCDriver.hex(bs));
			hex.append('#');
		}
		return encrypt(hex.toString(), key);
	}

	public static List<byte[]> decryptKeys(String cipher, String key) {
		String plain = decrypt(cipher, key);
		String[] ks = plain.split("#");
		List<byte[]> keys = new ArrayList<byte[]>();
		for (int i = 0; i < ks.length; i++) {
			keys.add(i, PBCDriver.unhex(ks[i]));
		}
		return keys;
	}

}
